package com.campus.utils;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    private Integer code;

    private Object data;

    private String msg;

    public static R success(String msg, Object data) {
        return new R(200, data, msg);
    }

    public static R success(Object data) {
        return new R(200, data, "操作成功");
    }

    public static R success() {
        return new R(200, null, "操作成功");
    }

    public static R error(String msg) {
        return new R(500, null, msg);
    }

    public static R error() {
        return new R(500, null, "操作失败");
    }

    public static R to(boolean b) {
        return b ? R.success() : R.error();
    }
}